package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 统计报表服务
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    /**
     * 获得运营数据
     * @return
     */
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception{
        Map<String, Object> map=new HashMap<>();
        //当前日期 reportDate
        Date date = DateUtils.getToday();
        String today = DateUtils.parseDate2String(date);
        //获得本周一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获得本月一号的日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //当前日期 reportDate
        map.put("reportDate",today);
        //今日新增会员数 todayNewMember
        Integer todayNewMember =memberDao.findMemberCountByDate(today);
        map.put("todayNewMember",todayNewMember);
        //总会员数 totalMember
        Integer totalMember=memberDao.findTotalMemberCount();
        map.put("totalMember",totalMember);
        //本周新增会员数 thisWeekNewMember
        Integer thisWeekNewMember =memberDao.findMemberCountAfterDate(thisWeekMonday);
        map.put("thisWeekNewMember",thisWeekNewMember);
        //本月新增会员数 thisMonthNewMember
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);
        map.put("thisMonthNewMember",thisMonthNewMember);
        //今日预约数 todayOrderNumber
        Integer todayOrderNumber =orderDao.findOrderCountByDate(today);
        map.put("todayOrderNumber",todayOrderNumber);
        //今日到诊数 todayVisitsNumber
        Integer todayVisitsNumber=orderDao.findVisitsCountByDate(today);
        map.put("todayVisitsNumber",todayVisitsNumber);
        //本周预约数 thisWeekOrderNumber
        Integer thisWeekOrderNumber=orderDao.findOrderCountAfterDate(thisWeekMonday);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        //本周到诊数 thisWeekVisitsNumber
        Integer thisWeekVisitsNumber=orderDao.findVisitsCountAfterDate(thisWeekMonday);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        //本月预约数 thisMonthOrderNumber
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        //本月到诊数 thisMonthVisitsNumber
        Integer thisMonthVisitsNumber=orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        //热门套餐 hotSetmeal
        List<Map> list=orderDao.findHotSetmeal();
        map.put("hotSetmeal",list);
        return map;
    }
}
